Ext.define('KaoQinQueryView', {
	extend : 'Ext.panel.Panel',
	id : 'KaoQinQueryView',
	title : '历史缺勤查询',
	region : 'center',
	layout : 'border',
	iconCls: 'menu-cusLinkman',

	initComponent : function() {		
		this.searchPanel = new KE.SearchPanel({
					region : 'north',
					items : [{
								text : '学号'
							}, {
								width : 120,
								name : 'Q_LIKES_course.name',
								xtype : 'textfield'
							}, {
								text : '日期'
							}, {
								width : 120,
								name : 'Q_GED_cdate',
								xtype : 'datefield',
								format: 'Y-m-d'
							}, {
								text : '~'
							}, {
								width : 120,
								name : 'Q_LED_cdate',
								xtype : 'datefield',
								format: 'Y-m-d'
							}, {
								text : '年级'
							}, {
								width : 120,
								hiddenName : 'Q_EQL_clazz.grade.oid',
								xtype : 'combo',
								valueField : 'oid',
								displayField : 'name',
								queryMode : 'local',
								editable: false,
								triggerAction : 'all',
								store : new Ext.data.JsonStore({
											autoLoad : true,
											fields : ['oid', 'name'],
											proxy : {
												type : 'ajax',
												url : __ctxPath + '/xskq/comboGrade.do',
												reader : {
													rootProperty : 'result'
												}
											}
										})	
							}, {
								xtype : 'button',
								text : '查询',
								scope : this,
								iconCls : 'btn-search',
								handler : this.search
							}, {
								xtype : 'button',
								text : '清空',
								scope : this,
								iconCls : 'reset',
								handler : this.reset
							}]
				});

		this.gridPanel = new KE.GridPanel({
			region : 'center',
			exportable : true,
			exportCfg : {
				expSel : true,
				selId : 'oid',
				selUrl : __ctxPath + "/xskq/exportSelKaoQin.do",
				execl : true,
				pdf : false
			},
			url : __ctxPath + "/xskq/listKaoQin.do",
			sorters: [{
				property: 'cdate',
				direction: 'DESC'
			},{
				property: 'jieciType.dicId',
				direction: 'ASC'
			}],
			fields : ['oid', 'check', 'student', 'type', 'cdate', {
							name : 'clazz.grade.name',
							mapping : 'clazz.grade.name'
						}, {
							name : 'course.name',
							mapping : 'course.name'
						}, {
							name : 'clazz.name',
							mapping : 'clazz.name'
						}, {
							name : 'jieciType.itemValue',
							mapping : 'jieciType.itemValue'
						}, {
							name : 'teacher.fullname',
							mapping : 'teacher.fullname'
						}, {
							name : 'user.fullname',
							mapping : 'user.fullname'
						}],
			columns : [{
					header : 'ID',
					dataIndex : 'oid',
					hidden : true
				}, {
					header : '年级',
					dataIndex : 'clazz.grade.name'
				}, {
					header : '班级',
					dataIndex : 'clazz.name'
				}, {
					header : '日期',
					dataIndex : 'cdate'
				}, {
					header : '节次',
					dataIndex : 'jieciType.itemValue'
				}, {
					header : '课程',
					dataIndex : 'course.name'
				}, {
					header : '教师',
					dataIndex : 'teacher.fullname'
				}, {
					header : '学生',
					dataIndex : 'student',
					renderer: function(v) {
						if(v) return v.name;
					}
				}, {
					header : '缺勤类型',
					dataIndex : 'type',
					renderer: function(v, g, rec) {
						if(rec.data.allCome == 1) return '';
						if(v) return v.itemValue
					} 
				}, {
					header : '落实情况',
					dataIndex : 'check',
					renderer: function(v) {
						if(v==0) {
							return '<span class="bg-red">未落实</span>';
						} else if(v==1) {
							return '<span class="bg-blue">已落实</span>';
						} else if(v==2) {
							return '<span class="bg-green">（全勤）</span>';
						}
					}
				}]
		
		});

		this.items = [this.searchPanel, this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);
	},
	// 重置查询表单
	reset : function() {
		this.searchPanel.getForm().reset();
		Ext.each(this.searchPanel.query('combo'), function(c) {
			c.setValue('');
			c.setRawValue('');
		});
	},
	// 按条件搜索
	search : function() {
		$search({
			searchPanel : this.searchPanel,
			gridPanel : this.gridPanel
		});
	},
	// GridPanel行点击处理事件
	rowClick : function(grid, rec) {
		if(rec.data.check==2) return;
		new KaoQinCheckInfoForm({
			rec: rec.data
		}).show();
	},
	// 类别树节点点击
	orgTreeClick : function(view, node) {
		var oid = node.id;
		var name = node.data.text;
		this.gridPanel.setTitle('年级/班级：' + name);
		this.gridPanel.getStore().getProxy().url = __ctxPath + "/xskq/listKaoQin.do";
		var params = {};
		if(oid != 0) {
			if(oid.indexOf('g_') == 0) {
				oid = oid.substring(2);
				params = {'Q_EQL_student.grade.oid' : oid};
			} else {
				params = {'Q_EQL_student.clazz.oid' : oid};
			}
		}
		this.gridPanel.getStore().reload({params : params});
	}
	

});
